package data;

import java.util.Date;

import com.EntityName;
import com.Util;
import com.google.appengine.api.datastore.Entity;

public class User extends AbstractData {
	private long id = -1;

	private Salutation salutation;
	private String salutationString;
	private String firstName;
	private String lastName;
	private String address;
	private String countryCodeISO3;
	private String state;
	private String city;
	private String zipCode;
	private String phone;
	private String mobile;
	private String emergencyNumber;
	private String gender;
	private Date birthday;
	private String identificationNo;
	private String passportNumber;
	private String driverlicense;
	private String socialSecuritycard;
	private String bloodGroup;
	private String designation;
	private String email;
	private String password;
	private Date dateOfJoin;
	private String commentText;
	private Date lastStay;
	private String sessionid;
	private String counterId;
	private LanguageMaster language;
	private String languageString;
	public User() {
	}

	public User(long id) {
		this.id = id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Override
	public long getId() {
		return id;
	}

	public Salutation getSalutation() {
		if (salutation == null && !(salutationString == null || salutationString.isEmpty())) {
			Salutation s = new Salutation(Long.parseLong(salutationString));
			s.LoadData();
			salutation = s;
		}
		return salutation;
	}

	public void setSalutation(Salutation salutation) {
		this.salutationString = String.format("%d", salutation.getId());
		this.salutation = salutation;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getCountryCodeISO3() {
		return countryCodeISO3;
	}

	public void setCountryCodeISO3(String countryCodeISO3) {
		this.countryCodeISO3 = countryCodeISO3;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getEmergencyNumber() {
		return emergencyNumber;
	}

	public void setEmergencyNumber(String emergencyNumber) {
		this.emergencyNumber = emergencyNumber;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getIdentificationNo() {
		return identificationNo;
	}

	public void setIdentificationNo(String identificationNo) {
		this.identificationNo = identificationNo;
	}

	public String getBloodGroup() {
		return bloodGroup;
	}

	public void setBloodGroup(String bloodGroup) {
		this.bloodGroup = bloodGroup;
	}

	public String getDesignation() {
		return designation;
	}

	public void setDesignation(String designation) {
		this.designation = designation;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	public Date getDateOfJoin() {
		return dateOfJoin;
	}

	public void setDateOfJoin(Date dateOfJoin) {
		this.dateOfJoin = dateOfJoin;
	}

	public String getCommentText() {
		return commentText;
	}

	public void setCommentText(String commentText) {
		this.commentText = commentText;
	}
	public void setSalutationString(String salutationString) {
		this.salutationString = salutationString;
	}
	public String getPassportNumber() {
		return passportNumber;
	}

	public void setPassportNumber(String passportNumber) {
		this.passportNumber = passportNumber;
	}

	public String getDriverlicense() {
		return driverlicense;
	}

	public void setDriverlicense(String driverlicense) {
		this.driverlicense = driverlicense;
	}

	public String getSocialSecuritycard() {
		return socialSecuritycard;
	}

	public void setSocialSecuritycard(String socialSecuritycard) {
		this.socialSecuritycard = socialSecuritycard;
	}

	public Date getLastStay() {
		return lastStay;
	}

	public void setLastStay(Date lastStay) {
		this.lastStay = lastStay;
	}
	public String getSessionid() {
		return sessionid;
	}

	public void setSessionid(String sessionid) {
		this.sessionid = sessionid;
	}

	public String getSalutationString() {
		return salutationString;
	}

	public String getCounterId() {
		return counterId;
	}

	public void setCounterId(String counterId) {
		this.counterId = counterId;
	}

	public LanguageMaster getLanguage() {
		if (language == null && !(languageString == null || languageString.isEmpty())) {
			LanguageMaster s = new LanguageMaster(Long.parseLong(languageString));
			s.LoadData();
			language = s;
		}
		return language;
	}

	public void setLanguage(LanguageMaster language) {
		this.languageString = String.format("%d", language.getId());
		this.language = language;
	}

	public String getLanguageString() {
		return languageString;
	}

	public void setLanguageString(String languageString) {
		this.languageString = languageString;
	}

	@Override
	public Entity getEntity() {
		Entity item;
		if(this.key == null)
			item = new Entity(EntityName.User);
		else
			item = new Entity(this.key);
		
		item.setProperty("salutation", this.salutationString);
		item.setProperty("firstName", this.firstName);
		item.setProperty("lastName", this.lastName);
		item.setProperty("address", this.address);
		item.setProperty("countryCodeISO3", this.countryCodeISO3);
		item.setProperty("state", this.state);
		item.setProperty("city", this.city);
		item.setProperty("zipCode", this.zipCode);
		item.setProperty("phone", this.phone);
		item.setProperty("mobile", this.mobile);
		item.setProperty("emergencyNumber", this.emergencyNumber);
		item.setProperty("gender", this.gender);
		item.setProperty("birthday", this.birthday);
		item.setProperty("identificationNo", this.identificationNo);
		item.setProperty("passportNumber", this.passportNumber);
		item.setProperty("driverlicense", this.driverlicense);
		item.setProperty("socialSecuritycard", this.socialSecuritycard);
		item.setProperty("bloodGroup", this.bloodGroup);
		item.setProperty("designation", this.designation);
		item.setProperty("email", this.email);
		item.setProperty("password", this.password);
		item.setProperty("dateOfJoin", this.dateOfJoin);
		item.setProperty("commentText", this.commentText);
		item.setProperty("lastStay", this.lastStay);
		item.setProperty("sessionid", this.sessionid);
		item.setProperty("counterId", this.counterId);
		item.setProperty("language", this.languageString);
		return item;
	}
	@Override
	public void setEntity(Entity entity) {
		this.id = entity.getKey().getId();
		this.salutationString = (String) entity.getProperty("salutation");
		this.firstName = (String) entity.getProperty("firstName");
		this.lastName = (String) entity.getProperty("lastName");
		this.address = (String) entity.getProperty("address");
		this.countryCodeISO3 = (String) entity.getProperty("countryCodeISO3");
		this.state = (String) entity.getProperty("state");
		this.city = (String) entity.getProperty("city");
		this.zipCode = (String) entity.getProperty("zipCode");
		this.phone = (String) entity.getProperty("phone");
		this.mobile = (String) entity.getProperty("mobile");
		this.emergencyNumber = (String) entity.getProperty("emergencyNumber");
		this.gender = (String) entity.getProperty("gender");
		this.birthday = (Date) entity.getProperty("birthday");
		this.identificationNo = (String) entity.getProperty("identificationNo");
		this.passportNumber =(String) entity.getProperty("passportNumber");
		this.driverlicense=(String) entity.getProperty("driverlicense");
		this.socialSecuritycard=(String) entity.getProperty("socialSecuritycard");
		this.bloodGroup = (String) entity.getProperty("bloodGroup");
		this.designation = (String) entity.getProperty("designation");
		this.email = (String) entity.getProperty("email");
		this.password = (String) entity.getProperty("password");
		this.dateOfJoin = (Date) entity.getProperty("dateOfJoin");
		this.commentText = (String) entity.getProperty("commentText");
		if(entity.getProperty("lastStay") == null){
			this.lastStay = Util.addDays(new Date(), -1);
		}else{
			this.lastStay = (Date) entity.getProperty("lastStay");
		}
		this.sessionid = (String) entity.getProperty("sessionid");
		this.counterId = (String) entity.getProperty("counterId");
		this.languageString = (String) entity.getProperty("language");
		this.key = entity.getKey();
	}

	public void LoadData() {
		if (this.id > -1) {
			Entity entity = LoadData(EntityName.User, this.id);
			setEntity(entity);
		}
	}
}

